package com.kingwang.training.designpattern.memento;

import com.kingwang.training.designpattern.memento.bo.game.GameMementoTaker;
import com.kingwang.training.designpattern.memento.bo.game.GamePlayer;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MementoApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(MementoApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 创建一个游戏角色
        GamePlayer player = new GamePlayer(100, 0);

        // 存档
        GameMementoTaker caretaker = new GameMementoTaker();
        caretaker.setMemento(player.saveToMemento());

        // 不小心死掉了
        player.play(-100, 10);

        // 读档
        player.restoreFromMemento(caretaker.getMemento());
    }
}
